#ifndef __state_h__
#define __state_h__

#include <stdio.h>
#include "types.h"

//class to save/load the current state, or do other saving/loading tasks
class CState
	{
	protected:
		FILE *fp;							//current file
	protected:
		char *MakeFilename(char *dest,int slot,char *fn);
	public:
		CState();
		virtual ~CState(){}
		int Save(int s,char *fn);		//start save state in slot s, rom base filename = fn
		int Load(int s,char *fn);		//start load state in slot s, rom base filename = fn
		int Load(char *fn);				//start load state from fn
		void Close();						//stop saving/loading
		u32 FilePos();						//position in file
		void WriteHeader(u8 ver);		//write state header
		void Write(u8 *data,int len);	//write len bytes out
		void Write8(u8 data);			//write 8 bits
		void Write16(u16 data);			//write 16 bits
		void Write32(u32 data);			//write 32 bits
		void Write64(u64 data);			//write 64 bits
		u8 ReadHeader();					//read state header, returns version
		int Read(u8 *data,int len);	//read in len bytes to data
		u8 Read8();							//read 8 bits
		u16 Read16();						//read 16 bits
		u32 Read32();						//read 32 bits
		u64 Read64();						//read 64 bits
	};

class CHighScore:public CState
	{
	public:
		CHighScore();
		~CHighScore();
		int Load(char *fn);
		int Save(char *fn);
	};

class CNVRAM:public CState
	{
	protected:
		char Name[32];
		u8 *Ptr;
		u32 Size;
	public:
		CNVRAM(char *n,u8 *p,u32 s);
		~CNVRAM();
		int Load();
		int Save();
		void SetData(char *n,u8 *p,u32 s);
	};

#endif
